<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8" isELIgnored="false"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>

    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">


    <title>修改作品</title>
    <meta name="keywords" content="">
    <meta name="description" content="">
    <link rel="shortcut icon" href="favicon.ico"> 
    <link href="${pageContext.request.contextPath }/css/bootstrap.min.css?v=3.3.6" rel="stylesheet">
    <link href="${pageContext.request.contextPath }/css/font-awesome.css?v=4.4.0" rel="stylesheet">
    <!-- jqgrid-->
    <link href="${pageContext.request.contextPath }/css/plugins/jqgrid/ui.jqgrid.css?0820" rel="stylesheet">
    <link href="${pageContext.request.contextPath }/css/animate.css" rel="stylesheet">
    <link href="${pageContext.request.contextPath }/css/style.css?v=4.1.0" rel="stylesheet">
    <script src="${pageContext.request.contextPath }/js/jquery.min.js?v=2.1.4"></script>
    <script src="${pageContext.request.contextPath }/js/bootstrap.min.js?v=3.3.6"></script>
    
    <!-- 自定义js -->
    <script src="${pageContext.request.contextPath }/js/content.js?v=1.0.0"></script>
    <!-- jQuery Validation plugin javascript-->
    <script src="${pageContext.request.contextPath }/js/plugins/validate/jquery.validate.min.js"></script>
    <script src="${pageContext.request.contextPath }/js/plugins/validate/messages_zh.min.js"></script>
    <script src="${pageContext.request.contextPath }/js/plugins/layer/layer.min.js"></script>
    
	<style>
		input,select{
			 width:168px;
			 height:25px;
			 border:1px solid #ccc;
			 margin-left:24px;
		}
		.label-text{
			width:80px;
			text-align:right;
		}
	</style>
</head>

<body class="gray-bg">
    <div class="wrapper wrapper-content  animated fadeInRight">
        <div class="row">
            <div class="col-sm-6">
                <div class="social-feed-box">
                    <div class="social-footer">
						<form name = "form1" id = "update_money_type" >
							<input type = "hidden" name = "id" id = "id" value = "${mt.id }"/><br/><br/>
							<input type = "hidden" name = "type" id = "type" value = "${mt.type }"/><br/><br/>
							<c:if test="${mt.type != 2}" >
								<label class="label-text">最小值：</label>
									<input type = "text" id = "minMoney" name = "minMoney" value = "${mt.minMoney }"  placeholder="输入最少分值"  ><br/><br/>
	                    		<label class="label-text">最大值：</label>
									<input type = "text" id = "maxMoney" name = "maxMoney" value = "${mt.maxMoney }"  placeholder="输入最多分值"  ><br/><br/>
							</c:if>
							<c:if test="${mt.type == 2}" >
								<input type = "hidden" id = "minMoney" name = "minMoney" value = "${mt.minMoney }"  placeholder="输入最少分值"  ><br/><br/>
	                    		<label class="label-text">当天最大值：</label>
									<input type = "text" id = "maxMoney" name = "maxMoney" value = "${mt.maxMoney }"  placeholder="输入最多分值" ><br/><br/>
							</c:if>
							<button class="btn btn-primary saveBtn" type="submit">保存</button>
					    </form>
                    </div>
                </div>
            </div>
        </div>
    </div>

</body>

    
    <script type="text/javascript">

    $().ready(function () {
        var icon = "<i class='fa fa-times-circle'></i> ";
        $("#update_money_type").validate({
            rules: {
            	minMoney: {//姓名
            		digits:true,
    				maxlength: 2
                },
                maxMoney: {//登录帐号
                	digits:true,
    				maxlength: 2
                }
            },
            messages: {
            	minMoney:{
            		required:icon + "请填写最小值",
            		maxlength:icon + "最大长度为2"
            	},
            	maxMoney: {
            		required:icon + "请填写最大值",
            		maxlength:icon + "最大长度为2"
                }
                
            },
    		submitHandler: function(form) {
	 			updateMoney();
    		}
        });
    });
 
 	function cancel(){
 		var index = parent.layer.getFrameIndex(window.name); //获取窗口索引
        parent.layer.close(index);
 	}
	//修改或修改
	function updateMoney(){	
		var min = $("#minMoney").val();
		var max = $("#maxMoney").val();
		if(parseInt(max) < parseInt(min)){
			alert("最大值应大于最小值");
			return ;
		}else{
			var formData = new FormData($( "#update_money_type" )[0]);  
			$.ajax({
				processData: false,
				contentType: false,
	    		url:"${pageContext.request.contextPath }/admin/moneyType/update",
	    		data:formData,
	    		type:"post",
	    		success:function(data){
                	if(data.code == 0){
                		layer.msg(data.message,{icon:1});
						setTimeout('cancel()',1000);
                	}else{
                		layer.msg(data.message,{icon:0});
                	}
	    		}
	    	});
		}
	}
	</script>
</html>
